Skip to content

Tests: Use assertNotSame() for scalar comparisons in file tests - #14857

Closed
hmbashar wants to merge 1 commit into
WordPress:trunkfrom
hmbashar:64895/file
Closed

hmbashar wants to merge 1 commit into
WordPress:trunkfrom
hmbashar:64895/file

Conversation

@hmbashar

Copy link
Copy Markdown

Description

Converts assertNotEquals() to assertNotSame() in tests/phpunit/tests/file.php where values are scalar (strings, URLs, integers, booleans). Follow-up to Trac #64895.

assertNotSame() is stricter — it checks both value and type equality, preventing false passes from type coercion.

Changes

  • tests/phpunit/tests/file.php: Replace assertNotEquals() with assertNotSame() for scalar comparisons

How to test

  1. Run the affected test class: phpunit tests/phpunit/tests/file.php
  2. All tests should pass

See Trac #64895

Use of AI Tools

AI assistance: Yes
Tool(s): Claude
Model(s): claude-sonnet-5-5
Used for: Code implementation and test; reviewed and verified by contributor.

@github-actions

Copy link
Copy Markdown

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs.

Core Committers: Use this line as a base for the props when committing in SVN:

Props hmbashar.

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.


Props Bot commands

You can trigger Props Bot actions by commenting on this PR:

  • @propsbot add <username> to give props to a GitHub user. Requires write access.
  • @propsbot remove <username> to leave a user out of the props. Requires write access.
  • @propsbot refresh to refresh this list. Adding the props-bot label works too.

@mukeshpanchal27 mukeshpanchal27 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The change looks good. wp_unique_filename() always returns a string, so assertNotSame() behaves the same as assertNotEquals() here. It also matches the other strict comparison commits for #64895. This was the only assertNotEquals() call in file.php.

One small note on the description, which does not block this change. For a "not" assertion, assertNotSame() is the less strict choice. For example, assertNotSame( 1, "1" ) passes, but assertNotEquals( 1, "1" ) fails. The change is still right for consistency, but the "prevents false passes" sentence does not apply to this assertion.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

No active review issues are reported for the test-only assertion change.

No open issues 🎉

What changed in this PR

Updates the file uniqueness test to use an identity-based comparison for generated filenames, following the assertion cleanup associated with Trac #64895.

Changes:

  • Replaces assertNotEquals() with assertNotSame() when comparing two generated filenames.
  • Changes only the test assertion; production code is unchanged.
File Description
tests/​phpunit/​tests/​file.php Uses assertNotSame() to check that generated filenames differ.

Review effort: Balanced

@lancewillett lancewillett left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Both generated filenames are strings, so this preserves the uniqueness check while using the strict comparison convention.

Reviewed with the unit-tests audit. The affected classes passed locally in single-site and multisite with random-order seeds 14610 and 64895; PHPCS and CI are green. Copilot reported no open issues.

AI review · gpt-6

wporg-sync pushed a commit that referenced this pull request Oct 27, 2026
Use `assertNotSame()` when comparing the two filename strings returned by `wp_unique_filename()`. Preserve the checks that both files can be created and written.

Developed in: #14857

Props hmbashar, mukesh27.
See #64895.


git-svn-id: https://develop.svn.wordpress.org/trunk@64825 602fd350-edb4-49c9-b593-d223f7449a82
@lancewillett

Copy link
Copy Markdown
Member

wporg-sync pushed a commit to WordPress/WordPress that referenced this pull request Oct 27, 2026
Use `assertNotSame()` when comparing the two filename strings returned by `wp_unique_filename()`. Preserve the checks that both files can be created and written.

Developed in: WordPress/wordpress-develop#14857

Props hmbashar, mukesh27.
See #64895.

Built from https://develop.svn.wordpress.org/trunk@64825


git-svn-id: http://core.svn.wordpress.org/trunk@63975 1a063a9b-81f0-0310-95a4-ce76da25c4cd
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants